package com.tudouji.project.system.service.impl;

import java.util.List;

import com.tudouji.common.utils.StringUtils;
import com.tudouji.project.organization.domain.Department;
import com.tudouji.project.organization.mapper.DepartmentMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.tudouji.project.system.mapper.EmployeeMapper;
import com.tudouji.project.system.domain.Employee;
import com.tudouji.project.system.service.IEmployeeService;

/**
 * 员工管理Service业务层处理
 * 
 * @author wf
 * @date 2021-01-22
 */
@Service
public class EmployeeServiceImpl implements IEmployeeService 
{
    @Autowired
    private EmployeeMapper employeeMapper;
    @Autowired
    private DepartmentMapper departmentMapper;

    /**
     * 查询员工管理
     * 
     * @param id 员工管理ID
     * @return 员工管理
     */
    @Override
    public Employee selectEmployeeById(Long id)
    {
        return employeeMapper.selectEmployeeById(id);
    }

    /**
     * 查询员工管理列表
     * 
     * @param employee 员工管理
     * @return 员工管理
     */
    @Override
    public List<Employee> selectEmployeeList(Employee employee)
    {
        return employeeMapper.selectEmployeeList(employee);
    }

    /**
     * 新增员工管理
     * 
     * @param employee 员工管理
     * @return 结果
     */
    @Override
    public int insertEmployee(Employee employee)
    {
        if (StringUtils.isNotBlank(employee.getDeparid())){
            Department department = departmentMapper.selectDepartmentById(employee.getDeparid());
            employee.setDepartname(department.getName());
        }
        return employeeMapper.insertEmployee(employee);
    }

    /**
     * 修改员工管理
     * 
     * @param employee 员工管理
     * @return 结果
     */
    @Override
    public int updateEmployee(Employee employee)
    {
        if (StringUtils.isNotBlank(employee.getDeparid())){
            Department department = departmentMapper.selectDepartmentById(employee.getDeparid());
            employee.setDepartname(department.getName());
        }
        return employeeMapper.updateEmployee(employee);
    }

    /**
     * 批量删除员工管理
     * 
     * @param ids 需要删除的员工管理ID
     * @return 结果
     */
    @Override
    public int deleteEmployeeByIds(Long[] ids)
    {
        return employeeMapper.deleteEmployeeByIds(ids);
    }

    /**
     * 删除员工管理信息
     * 
     * @param id 员工管理ID
     * @return 结果
     */
    @Override
    public int deleteEmployeeById(Long id)
    {
        return employeeMapper.deleteEmployeeById(id);
    }
}
